//
//  DSSHMeMainVC.m
//  DSSH
//
//  Created by lcy on 16/3/28.
//  Copyright © 2016年 lcy. All rights reserved.
//

#import "DSSHMeMainVC.h"
#import "UIView+Round.h"
#import "DSSHMeWalletVC.h"
#import "MeButton.h"
#import "DSSHMeTaskVC.h"
#import "DSSHMeRepairsVC.h"
#import "DSSHMeMediateVC.h"
#import "DSSHMeInfoVC.h"
#import "DSSHMeCollectVC.h"
#import "DSSHInviteVC.h"
#import "DSSHMeFooterPrintVC.h"
#import "DSSHMeCommentVC.h"
#define ME_TABLE_INFO_CELL_HEIGHT 150
#define ME_TABLE_CELL_HEIGHT 44
@interface DSSHMeMainVC ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView* meMainTableView;
@end

@implementation DSSHMeMainVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupViewAndData];
    
    // Do any additional setup after loading the view.
}
-(void)setupViewAndData
{
    self.title = @"媒体铺子";
    self.view.backgroundColor = [UIColor whiteColor];
    self.meMainTableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
    self.meMainTableView.delegate = self;
    self.meMainTableView.dataSource = self;
    self.meMainTableView.tableFooterView = [[UIView alloc]init];
    [self.view addSubview:self.meMainTableView];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 1;
    }else if (section == 1)
    {
        return 2;
    }else
    {
        return 3;
    }
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellID = @"cellID";
    NSMutableArray * array1 = [[NSMutableArray alloc]initWithObjects:@"我的钱包",@"我的报修",@"调处", nil];
    NSMutableArray * array2 = [[NSMutableArray alloc]initWithObjects:@"我的消息",@"我的足迹",@"邀请好友", nil];
    NSMutableArray * imageArray1 = [[NSMutableArray alloc]initWithObjects:@"iconfont_wodeqianbao01",@"iconfont_dajianshangpinbaoxiuchaxun",@"iconfont_101", nil];
    NSMutableArray * imageArray2 = [[NSMutableArray alloc]initWithObjects:@"xiaoxi",@"iconfont_zuji1",@"iconfont_yaoqing", nil];
    
    NSMutableArray * tableDataArray = [[NSMutableArray alloc]initWithObjects:array1,array2, nil];
    NSMutableArray * tableImageArry = [[NSMutableArray alloc]initWithObjects:imageArray1,imageArray2, nil];
    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
        cell.textLabel.font = FONT(13);
        cell.detailTextLabel.font = FONT(13);
    }
    if (indexPath.section == 0)
    {
        if (indexPath.row == 0)
        {
            UIImageView * bgImageView = [UIImageView new];
            [cell.contentView addSubview:bgImageView];
            bgImageView.image = [UIImage imageNamed:@"bg"];
            bgImageView.userInteractionEnabled = YES;
            UIImageView * headImageView = [UIImageView new];
            [headImageView getRoundView:30*WIDTH_SCALE];
            headImageView.image = [UIImage imageNamed:@"touxiang"];
            [bgImageView addSubview:headImageView];
            
            UILabel * nameLabel = [UILabel new];
            nameLabel.font = FONT(14);
            nameLabel.text = @"1820000000";
            [bgImageView addSubview:nameLabel];
            
            UILabel * gradeLabel = [UILabel new];
            gradeLabel.textColor = [UIColor grayColor];
            gradeLabel.text = @"普通会员";
            gradeLabel.font = FONT(13);
            [bgImageView addSubview:gradeLabel];
            
            UIButton * gradeBtn = [UIButton new];
            [gradeBtn setTitle:@"升级" forState:UIControlStateNormal];
            [gradeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            gradeBtn.titleLabel.font = FONT(13);
            [gradeBtn setBackgroundColor:RGBA(164, 221, 255, 1)];
            [gradeBtn addTarget:self action:@selector(clickGradeBtn) forControlEvents:UIControlEventTouchUpInside];
            [bgImageView addSubview:gradeBtn];
            
            UIView * bottomView = [UIView new];
            bottomView.backgroundColor = [[UIColor grayColor]colorWithAlphaComponent:0.3];
            [bgImageView addSubview:bottomView];
            
            MeButton * btn1 = [MeButton new];
            btn1.numLabel.text = @"10";
            btn1.tag = 1;
            btn1.describeLabel.text = @"互动";
            [btn1 addTarget:self action:@selector(clickInteractionBtn:) forControlEvents:UIControlEventTouchUpInside];
            [bottomView addSubview:btn1];
            
            MeButton * btn2 = [MeButton new];
            [btn2 addTarget:self action:@selector(clickInteractionBtn:) forControlEvents:UIControlEventTouchUpInside];
            btn2.numLabel.text = @"331";
            btn2.tag = 2;
            btn2.describeLabel.text = @"评论";
            [bottomView addSubview:btn2];
            MeButton * btn3 = [MeButton new];
            btn3.numLabel.text = @"10";
            btn3.tag = 3;
            [btn3 addTarget:self action:@selector(clickInteractionBtn:) forControlEvents:UIControlEventTouchUpInside];
            btn3.describeLabel.text = @"收藏";
            [bottomView addSubview:btn3];
            
            UIView* lineView1 = [UIView new];
            lineView1.backgroundColor = [UIColor whiteColor];
            [btn2 addSubview:lineView1];
            UIView* lineView2 = [UIView new];
            lineView2.backgroundColor = [UIColor whiteColor];
            [btn2 addSubview:lineView2];
            [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(cell.contentView).with.offset(0);
                make.top.equalTo(cell.contentView).with.offset(0);
                make.width.mas_equalTo(cell.contentView.mas_width);
                make.height.mas_equalTo(cell.contentView.mas_height);
            }];
            
            [headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(bgImageView.mas_left).with.offset(25*WIDTH_SCALE);
                make.top.equalTo(bgImageView.mas_top).with.offset(30*HIGHT_SCALE);
                make.size.mas_equalTo(CGSizeMake(60*WIDTH_SCALE, 60*WIDTH_SCALE));
            }];
            [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(headImageView.mas_right).with.offset(10*WIDTH_SCALE);
                make.top.equalTo(headImageView.mas_top).with.offset(10*HIGHT_SCALE);
                make.width.mas_equalTo(200*WIDTH_SCALE);
                make.height.mas_equalTo(20*HIGHT_SCALE);
                
            }];
            [gradeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(headImageView.mas_right).with.offset(10*WIDTH_SCALE);
                make.top.equalTo(nameLabel.mas_bottom).with.offset(0);
                make.width.mas_equalTo(200*WIDTH_SCALE);
                make.height.mas_equalTo(20*HIGHT_SCALE);
                
            }];
            [gradeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(headImageView.mas_right).with.offset(10*WIDTH_SCALE);
                make.top.equalTo(gradeLabel.mas_bottom).with.offset(0);
                make.width.mas_equalTo(50*WIDTH_SCALE);
                make.height.mas_equalTo(20*HIGHT_SCALE);
                
            }];
            
            [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(bgImageView.mas_left).with.offset(0);
                make.bottom.equalTo(bgImageView.mas_bottom).with.offset(0);
                make.width.mas_equalTo(bgImageView.mas_width);
                make.height.mas_equalTo(40*HIGHT_SCALE);
            }];
            
            [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(bottomView.mas_left).with.offset(20*WIDTH_SCALE);
                make.bottom.equalTo(bottomView.mas_bottom).with.offset(-3*HIGHT_SCALE);
                make.width.mas_equalTo((ZYAppWidth-40*WIDTH_SCALE)/3);
                make.height.mas_equalTo(40*HIGHT_SCALE);
            }];
            [btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(bottomView.mas_right).with.offset(-20*WIDTH_SCALE);
                make.bottom.equalTo(bottomView.mas_bottom).with.offset(-3*HIGHT_SCALE);
                make.width.mas_equalTo((ZYAppWidth-40*WIDTH_SCALE)/3);
                make.height.mas_equalTo(40*HIGHT_SCALE);
            }];
            [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(btn1.mas_right).with.offset(0);
                make.bottom.equalTo(bottomView.mas_bottom).with.offset(-3*HIGHT_SCALE);
                make.width.mas_equalTo((ZYAppWidth-40*WIDTH_SCALE)/3);
                make.height.mas_equalTo(40*HIGHT_SCALE);
            }];
            [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(btn2.mas_left).with.offset(0);
                make.width.mas_equalTo(1*WIDTH_SCALE);
                make.top.equalTo(btn2.mas_top).with.offset(5*HIGHT_SCALE);
                make.bottom.equalTo(btn2.mas_bottom).with.offset(-5*HIGHT_SCALE);
            }];
            [lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(btn2.mas_right).with.offset(0);
                make.width.mas_equalTo(1*WIDTH_SCALE);
                make.top.equalTo(btn2.mas_top).with.offset(5*HIGHT_SCALE);
                make.bottom.equalTo(btn2.mas_bottom).with.offset(-5*HIGHT_SCALE);
            }];

        }
        
    }else if (indexPath.section == 1)
    {
        if (indexPath.row == 0)
        {
            cell.textLabel.text = @"我的任务";
            cell.detailTextLabel.text = @"查看全部任务";
            cell.imageView.image = [UIImage imageNamed:@"iconfont_renwu-0"];
            [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        }else
        {
            UIButton * finishedTaskBtn = [UIButton new];
            [finishedTaskBtn setTitle:@"我做的任务" forState:UIControlStateNormal];
            [finishedTaskBtn addTarget:self action:@selector(clickFinishedTaskBtn) forControlEvents:UIControlEventTouchUpInside];
            [finishedTaskBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            finishedTaskBtn.titleLabel.font = FONT(13);
            [finishedTaskBtn getRoundView:5];
            finishedTaskBtn.layer.borderWidth = 1;
            finishedTaskBtn.layer.borderColor = [[UIColor grayColor]CGColor];
            [cell.contentView addSubview:finishedTaskBtn];
            
            [finishedTaskBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(cell.contentView.mas_left).with.offset(25*WIDTH_SCALE);
                make.centerY.mas_equalTo(cell.contentView.mas_centerY);
                make.height.mas_equalTo(30*HIGHT_SCALE);
                make.width.mas_equalTo((ZYAppWidth-25*4)/3);
            }];
        }
    }else
    {
        cell.textLabel.text = [tableDataArray objectAtIndex:indexPath.section-2][indexPath.row];
        cell.imageView.image = [UIImage imageNamed:[tableImageArry objectAtIndex:indexPath.section-2][indexPath.row]];
        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    }
    
    return cell;
}
#pragma 点击升级按钮
-(void)clickGradeBtn
{
    NSLog(@"升级");
}
#pragma 点击互动收藏按钮
-(void)clickInteractionBtn:(MeButton*)button
{
    if (button.tag == 2)
    {
        //评论
        DSSHMeCommentVC * commentVC = [[DSSHMeCommentVC alloc]init];
        [self.navigationController pushViewController:commentVC animated:YES];
        
    }
    if (button.tag == 3)
    {
        DSSHMeCollectVC * collectVC = [[DSSHMeCollectVC alloc]init];
        [self.navigationController pushViewController:collectVC animated:YES];
    }
    
    
}
-(void)clickFinishedTaskBtn
{
    DSSHMeTaskVC * taskVC = [[DSSHMeTaskVC alloc]init];
    [self.navigationController pushViewController:taskVC animated:YES];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        return ME_TABLE_INFO_CELL_HEIGHT*HIGHT_SCALE;
        
    }else
    {
        if (indexPath.section == 1)
        {
            if (indexPath.row == 1)
            {
                return 60*HIGHT_SCALE;
            }
        }
         return ME_TABLE_CELL_HEIGHT*HIGHT_SCALE;
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 5*HIGHT_SCALE;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 0)
    {
        DSSHMeInfoVC * infoVC = [[DSSHMeInfoVC alloc]init];
        [self.navigationController pushViewController:infoVC animated:YES];
    }
    if (indexPath.section == 2)
    {
        if (indexPath.row == 0)
        {
            DSSHMeWalletVC * walletVC = [[DSSHMeWalletVC alloc]init];
            [self.navigationController pushViewController:walletVC animated:YES];
        }
        if (indexPath.row == 1)
        {
            DSSHMeRepairsVC * repairsVC = [[DSSHMeRepairsVC alloc]init];
            [self.navigationController pushViewController:repairsVC animated:YES];
        }
        if (indexPath.row == 2)
        {
            DSSHMeMediateVC * mediateVC = [[DSSHMeMediateVC alloc]init];
            [self.navigationController pushViewController:mediateVC animated:YES];
        }
    }
    if (indexPath.section == 3)
    {
        if (indexPath.row == 1)
        {
            DSSHMeFooterPrintVC * footerVC = [[DSSHMeFooterPrintVC alloc]init];
            [self.navigationController pushViewController:footerVC animated:YES];
        }
        if (indexPath.row == 2)
        {
            DSSHInviteVC * inviteVC = [[DSSHInviteVC alloc]init];
            [self.navigationController pushViewController:inviteVC animated:YES];
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
